package com.spring.demo.springdemo;

//import com.spring.demo.springdemo.config.MybatisMainConfig;
import com.spring.demo.springdemo.config.MybatisMainConfig;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

//@EnableAspectJAutoProxy
@SpringBootApplication(scanBasePackages = "com.spring.demo")
public class SpringDemoApplication {

    public static void main(String[] args) {


//
//        /**================= spring xml配置装配方式，通过ClassPathXmlApplicationContext解析xml获取容器实例========================**/
//        ClassPathXmlApplicationContext cxt=new ClassPathXmlApplicationContext();
//        cxt.setConfigLocation("classpath:bean.xml");
//        cxt.setAllowCircularReferences(false);
//        cxt.refresh();
//        System.out.println("============通过xml配置获取容器的实例结果为==========="+cxt.getBean("car"));



        /**================spring Annotation配置装配方式，通过AnnotationConfigApplicationContext解析注解获取容器实例======================**/
        AnnotationConfigApplicationContext annotationAppContext=new AnnotationConfigApplicationContext();

        annotationAppContext.register(MybatisMainConfig.class);
//        System.out.println("============通过 Annotation配置获取容器的实例结果为=====person2======"+apc.getBean("person"));
//
//        System.out.println("============通过 Annotation配置获取容器的实例结果为=====responseResult======"+apc.getBean("responseResult"));
//
//        ApplicationContext applicationContext =  new AnnotationConfigApplicationContext(MybatisMainConfig.class);
//        applicationContext.getBean("person");
//

//        //将普通java对象，封装为beanDefinition 注册到容器中
//        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//
//        beanDefinition.setBeanClass(GoodService.class);
//        beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("苹果16 PLUS");
////        beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
//        apc.registerBeanDefinition("goodService",beanDefinition);


        annotationAppContext.refresh();

        annotationAppContext.publishEvent("123456");   //发布事件

        Object zzz = annotationAppContext.getBean("ZZZ");
        System.out.println(zzz);

        UserService userService = (UserService)annotationAppContext.getBean("userService");
        userService.test("1111","1232132");

//        apc.close();

    }

}
